package lium.lbs.lbsim.activity

import android.content.Intent
import android.graphics.Paint
import android.os.Bundle
import android.view.View
import com.buz.hjcdriver.bean.EstablishQunBean
import com.buz.hjcdriver.bean.GetOrderSNBean
import com.lmlibrary.Constants
import com.lmlibrary.bean.ResponseBean
import com.lzy.okgo.model.Response
import kotlinx.android.synthetic.main.activity_creategroup.*
import kotlinx.android.synthetic.main.activity_creategroup_pay.*
import kotlinx.android.synthetic.main.activity_registuserpwd.*
import lium.lbs.lbsim.R
import lium.lbs.lbsim.bean.GroupInfoBean
import lium.lbs.lbsim.jgchat.application.GJApp
import lium.lbs.lbsim.jgchat.utils.photovideo.takevideo.utils.LogUtils
import lium.lbs.lbsim.pay.ChoosePayWayActivity
import lium.lbs.lbsim.pay.alipayutils.ZFBActivity
import lium.lbs.lbsim.pay.weixinpay.WXPayActivity
import lium.lbs.lbsim.utils.SpUtils
import lium.lbs.lbsim.utils.callbck.DialogCallback
import java.util.HashMap

class CreateGroupPayActivity : BaseActivity() {

    var name: String? = null
    var orderSN: String? = null
    var mygroupID: String? = null

    override fun getLayoutId(): Int {
        return R.layout.activity_creategroup_pay
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitleWithBack("支付")
        name = intent.getStringExtra("name")
        addOnClickListeners(R.id.btn_creategroup_pay)
        old_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
    }


    override fun getNetWorkData() {
        getDataList()
    }


    fun getDataList() {
        val param = HashMap<String, String>()
        postData(
            "/group/getCreateGroupMoney",
            param,
            object : DialogCallback<ResponseBean<EstablishQunBean>>(this) {
                override fun onSuccess(response: Response<ResponseBean<EstablishQunBean>>) {
                    setDataList(response.body().data)
                }
            })
    }

    fun setDataList(establishQunBean: EstablishQunBean) {
        price.text = establishQunBean?.price
        old_price.text = establishQunBean?.oldPrice
        rule.text = establishQunBean?.content
    }

    override fun onClick(v: View?) {
        super.onClick(v)
        when (v!!.id) {
            R.id.btn_creategroup_pay -> {
                getOrderSN()

            }
        }
    }

    fun getOrderSN() {
        val param = HashMap<String, String>()
        param["memberId"] = SpUtils.getInstance().get(Constants.memberId, "") as String
        param["groupName"] = name.toString()
        param["price"] = price.text.toString()
        postData(
            "/group/createGroupOrder",
            param,
            object : DialogCallback<ResponseBean<GetOrderSNBean>>(this) {
                override fun onSuccess(response: Response<ResponseBean<GetOrderSNBean>>) {
                    setDataOrderSN(response.body().data)

                }
            })
    }

    fun setDataOrderSN(getOrderSNBean: GetOrderSNBean) {

        orderSN = getOrderSNBean?.orderSn
        mygroupID = getOrderSNBean?.groupId
        SpUtils.getInstance().put(Constants.groupIDLS, mygroupID)
        val intent = Intent(this, ChoosePayWayActivity::class.java)
        intent.putExtra("name", "建群支付")
        intent.putExtra("moeny", price.text.toString())
        intent.putExtra("orderSN", orderSN)
        startActivity(intent)
        finish()
    }






}

